package kuonta.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

@Entity
@Table(name = "tb_folhas")
public class FolhaContas {

	@EmbeddedId
	private FolhaContasId id;

	@OneToOne
	@JoinColumn(name="congregacao")
	private Congregacao congregacao;
			
	@OneToMany(cascade = { CascadeType.ALL }, fetch=FetchType.EAGER)  
    @Cascade(value = { org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )  
    @JoinTable(name="tb_itens_folhas",inverseJoinColumns = { @JoinColumn( name="id_item_folhas_contas")})
	private List<ItemFolhaContas> itensFolha = new ArrayList<ItemFolhaContas>();
	
	public FolhaContas() {
		
	}
	
	public FolhaContas(FolhaContasId id) {
		super();
		this.id = id;
	}

	public Congregacao getCongregacao() {
		return congregacao;
	}

	public void setCongregacao(Congregacao congregacao) {
		this.congregacao = congregacao;
	}

	public FolhaContasId getId() {
		return id;
	}

	public void setId(FolhaContasId id) {
		this.id = id;
	}

	public List<ItemFolhaContas> getItensFolha() {
		return itensFolha;
	}

	public void setItensFolha(List<ItemFolhaContas> itensFolha) {
		this.itensFolha = itensFolha;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FolhaContas other = (FolhaContas) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
